<SCRIPT LANGUAGE="JavaScript">  

    function swap(temp)
    {
        for(i=0;i<document.getElementById('jumlah').value;i++)
        {
            document.getElementById('check'+i).checked = temp.checked;
        }
    }
    
    function check_all()
    {
        for(i=0;i<document.getElementById('jumlah').value;i++)
        {
            document.getElementById('check'+i).checked = true;
        }
        document.getElementById('checkall').checked = true;
    }

    function uncheck_all()
    {
        for(i=0;i<document.getElementById('jumlah').value;i++)
        {
            document.getElementById('check'+i).checked = false;
        }
        document.getElementById('checkall').checked = false;
    }    
    


    var xx = 100;
    var yy = 100;
    var tx = 0;
    var ty = 0;
    var dx = 0;
    var dy = 0;
    var klik = 0;
    
    function make_slip()
    {  
        xx=670;
        yy=300;
        klik=0;
        
        var temp = document.getElementById('slip');
        temp.style.position = 'absolute';
        temp.style.borderTop = '4px solid #ddd';
        temp.style.borderLeft = '4px solid #ddd';
        temp.style.borderBottom = '4px solid #aaa';
        temp.style.borderRight = '4px solid #aaa';
            
        temp.style.top = '300px';
        temp.style.left = '670px';
        temp.style.width = 'auto';
        temp.style.height = 'auto';
        temp.style.backgroundColor = 'white';
    }
    
    function close_slip()
    {  
        document.getElementById('slip').innerHTML = '';
        document.getElementById('slip').style.border = 'none';
    }
    
    function tekan(event)
    {
        klik = 1;
        tx=event.clientX;
        ty=event.clientY;
    }
    
    function gerak(event)
    {
        if(klik==1)
        {
            dx=event.clientX-tx;
            dy=event.clientY-ty;
            
            xx = xx + dx;
            yy = yy + dy;
            
            document.getElementById('slip').style.top = yy+'px';
            document.getElementById('slip').style.left = xx+'px';      
            
            tx=event.clientX;
            ty=event.clientY;
        }
    }    
    
    function lepas()
    {
        klik=0;
    }

    function validation()
    {
        
        updateRTEs();
        document.getElementById('ApplicantReply').value=document.getElementById('hdnrtereply').value;
        
        var pass = false;
        for(i=0;i<document.getElementById('jumlah').value;i++)
        {
            if( document.getElementById('check'+i).checked == true )
            {
                pass = true;
                
            }
        
        }
        
        if(pass)
        { return confirm('Are you sure ?'); }
        else
        { alert('You must choose at least one of the applicant(s) to be accepted'); return false; }        
        
    }    
    
    function load()
    {
        document.getElementById('company_name').value
        frames['rtereply'].document.body.innerHTML="Dear [Jobseeker name]<br><br>Congratulations, you have been chosen to move forward for becoming our staff in the position <b>"+document.getElementById('position').value+"</b>. Please take our next interview, we are hopefully that you can participate.<br><br>Thank You, <b>"+document.getElementById('company_name').value+"</b>";
    } 
    
    function test()
    {
        frames['rtereply'].document.body.innerHTML+="[Jobseeker Name]"
    } 
    
    function open_win(id)
    {
        window.open('../../jobseekers/preview_resume/'+id,"_blank","toolbar=no, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, top=100, left=100, width=850, height=600");
    }     
    
        
    initRTE("../../app/webroot/js/images/", "../../app/webroot/js/", "../../app/webroot/js/");
        
</SCRIPT>
<?php

echo "<div class='form'>";
echo "<h2> Choosing Applicants </h2>";
echo "<hr color='#2A7EF7'>";
echo ":. Back to ".$html->link('[ My Jobs ]',array('controller'=>'jobs','action'=>'my_jobs'));
echo "<br>:. Back to ".$html->link('[ Resume Alert ]',array('controller'=>'applicants','action'=>'alert'));

if(!empty($applicants))
{ 
    echo $this->element('myfunction');
    
    echo $form->create('Applicant',array('action'=>'accept','onsubmit'=>'return validation();'));
    echo "<div class='kotak2' style='border:none;background-color:white;text-align:right;margin-left:90px'>";
        echo $form->input('jobid',array('type'=>'hidden','value'=>$job['jobs']['id']));
        echo $form->input('reply',array('type'=>'hidden'));
    ?>  
    <center style='margin-bottom:3px;'>   
    <SCRIPT language="JavaScript" type="text/javascript">
            writeRichText('rtereply', '', 450, 250, true, false);
    </SCRIPT>
    </center>
    <?php     
        echo "<input type='button' value='Load Example' onclick='load();'>&nbsp ";
        echo "<input type='button' value='Insert Name' onclick='test();'>&nbsp";
    echo "</div>";
        echo "<input type='hidden' id='company_name' value='".$job['employers']['company_name']."'>";
        echo "<input type='hidden' id='position' value='".$job['jobs']['position']."'>";
        
        echo "<input type='hidden' id='jumlah' value='".count($applicants)."'>";
        
        echo "&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp <b>.: The applicant(s) who have applied this job :.</b>";
        echo "<table class='jobs' cellpadding=0 cellspacing=0 style='margin-top:3px'>"; 
            echo "<tr> <th width='50px'><input type='checkbox' id='checkall' onClick='swap(this)'></th> <th width='85px'>Date Applied</th> <th width='195px'>Name</th><th width='30px'>Age</th><th width='100px'>Location</th><th width='120px'>Highest Acadmic</th><th width='110px'>Working Experience</th><th width='150px'>Resume</th><th width='150px'>Show</th> </tr>";
            //echo "<tr> <th width='50px'>&nbsp</th> <th width='85px'>Date Applied</th> <th width='195px'>Name</th><th width='30px'>Age</th><th width='100px'>Location</th><th width='120px'>Highest Acadmic</th><th width='110px'>Working Experience</th><th width='150px'>Resume</th><th width='150px'>Show</th> </tr>";
            $i=0;
            foreach($applicants as $applicant)
            {
                    echo "<tr>";   
                        if($applicant['applicants']['status']==0)
                        { echo "<td><input type='checkbox' id='check".$i."' name='data[".$applicant['applicants']['id']."]' ></td>"; }
                        else
                        { echo "<td><input type='checkbox' id='check".$i."' name='data[".$applicant['applicants']['id']."]' style='display:none' disabled='true'></td>"; }
                        $i++;
                        
                        echo "<td>".mydate($applicant['applicants']['created'])."</td>";
                        if($applicant['applicants']['status']==0 && $applicant['applicants']['viewed']==0)
                        { echo "<td>".$applicant['jobseekers']['salution']." ".$applicant['jobseekers']['first_name']." ".$applicant['jobseekers']['last_name']."<font color='red'><sup><b> NEW</b></sup></font></td>"; }
                        else   
                        { echo "<td>".$applicant['jobseekers']['salution']." ".$applicant['jobseekers']['first_name']." ".$applicant['jobseekers']['last_name']."</td>"; }   
                        echo "<td>".(date("Y") - substr($applicant['jobseekers']['date_of_birth'],0,4))."</td>";
                        echo "<td>".$applicant['cities']['name']."</td>";
                        if($applicant['applicants']['resume']==0)
                        { echo "<td>".$applicant['academics']['name']."</td>"; }
                        else
                        { echo "<td> - </td>"; }
                        if($applicant['applicants']['resume']==0)
                        { 
                            if($applicant['resumes']['work_exp']==0)
                            { echo "<td>Still School</td>"; }
                            if($applicant['resumes']['work_exp']==1)
                            { echo "<td>Fresh Graduate</td>"; }
                            if($applicant['resumes']['work_exp']==2)
                            { echo "<td>".$applicant['resumes']['year_exp']." year(s)</td>"; }
                        }
                        else
                        { echo "<td> - </td>"; }
                        
                        echo "<td>";
                        if($applicant['applicants']['resume']==0)
                        { 
                            echo "<a href='Javascript:open_win(".$applicant['applicants']['jobseeker_id'].")' class='sky'>Resume Online</a>";
                            //echo $html->link('Resume Online',array('controller'=>'resumes','action'=>'view','id'=>$applicant['resumes']['id']),array('class'=>'sky')); 
                        
                        }
                        else
                        { echo $html->link('Attachment Resume','../app/webroot/'.$applicant['resumes']['upload_file'],array('class'=>'sky'),false,false); }
                        echo "</td><td>";
                        if($applicant['applicants']['resume']==0)
                        {
                            /*
                            e(  $ajax->link( 'Cover', array('controller' => 'applicants', 'action' => 'show_cover', $applicant['applicants']['id']),
                                array('update' => 'status'.$applicant['applicants']['id'], 'loading' => "$('loader').show()", 'loaded' => "$('loader').hide()")));
                            e(  $ajax->link( 'Status', array('controller' => 'applicants', 'action' => 'status', $applicant['applicants']['id']),
                                array('update' => 'status'.$applicant['applicants']['id'], 'loading' => "$('loader').show()", 'loaded' => "$('loader').hide()")));
                            */    
                            echo  $ajax->link('[ Cover ]', array('controller'=>'applicants','action'=>'show_cover',$applicant['applicants']['id']), array('update'=>'slip','complete'=>"make_slip();"));                           
                            echo  $ajax->link('[ Status ]', array('controller'=>'applicants','action'=>'status',$applicant['applicants']['id']), array('update'=>'slip','complete'=>"make_slip();"));                           
                        }
                        else
                        { echo  $ajax->link('[ Cover ]', array('controller'=>'applicants','action'=>'show_cover',$applicant['applicants']['id']), array('update'=>'slip','complete'=>"make_slip();")); }
                        echo "</td>";
                    echo "</tr>";
            }
        echo "<tr class='end'><td class='end' colspan=9> &nbsp <a href='Javascript:check_all();'>[ Select All ]</a> &nbsp <a href='Javascript:uncheck_all();'>[ Unselect All ]</a> </td></tr>";
        //echo "<tr class='end'><td class='end' colspan=9> &nbsp </td></tr>";
        echo "</table>";
        
        //echo "<div class='input'><label> &nbsp </label><input type='submit' value='Submit'></div>";
        echo "&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp <input type='submit' value='Submit'>";
    echo "</form>";
}
else
{ echo "Sorry, There is no applicant who applied this job yet"; }


echo "</div>";
echo "<div id='slip'></div>";
?>    
